//===============================================================================
// Microsoft Architecture Strategy Team
// LitwareHR - SaaS Sample Application
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using System.Collections.Generic;
using System.Text;
using LitwareHR.Recruiting.Contract;
using System.ServiceModel;
using Shp.Runtime.Contract;

namespace LitwareHR.Portfolio.Gateways
{
    static public class RecruitingGateway
    {
        static public List<Guid> GetOpenPositionList(Guid tenantId)
        {
            using (UnSecureChannel channel = new UnSecureChannel())
            {
                return channel.GetOpenPositionList(tenantId);
            }
        }

        static public Guid OpenRecruitingProcess(Position position)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.OpenRecruitingProcess(position);
            }
        }

        static public StringPair[][] GetRecruitingWorkflowListByApplicant(bool isOpen)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.GetRecruitingWorkflowListByApplicant(isOpen);
            }
        }

        static public StringPair[][] GetRecruitingWorkflowList(bool isOpen)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                return channel.GetRecruitingWorkflowList(isOpen);
            }
        }

        static public void SubmitResume(Resume resume)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.SubmitResume(resume);
            }
        }

        static public void SubmitInterview(Interview interview)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.SubmitInterview(interview);
            }
        }

        static public void SubmitNegotiation(Negotiation negotiation)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.SubmitNegotiation(negotiation);
            }
        }

        static public void SubmitAcceptance(Acceptance acceptance)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.SubmitAcceptance(acceptance);
            }
        }

        static public void SubmitRejection(Rejection rejection)
        {
            using (SecureChannel channel = new SecureChannel())
            {
                channel.SubmitRejection(rejection);
            }
        }

        private class UnSecureChannel : ClientBase<IProcessUC>, IProcessUC
        {
            #region IProcessUC Members

            public List<Guid> GetOpenPositionList(Guid tenantId)
            {
                return base.Channel.GetOpenPositionList(tenantId);
            }

            #endregion
        }

        private class SecureChannel : ClientBase<IProcessSC>, IProcessSC
        {
            #region IProcessSC Members

            public Guid OpenRecruitingProcess(Position position)
            {
                return base.Channel.OpenRecruitingProcess(position);
            }

            public StringPair[][] GetRecruitingWorkflowListByApplicant(bool isOpen)
            {
                return base.Channel.GetRecruitingWorkflowListByApplicant(isOpen);
            }

            public StringPair[][] GetRecruitingWorkflowList(bool isOpen)
            {
                return base.Channel.GetRecruitingWorkflowList(isOpen);
            }

            public void SubmitResume(Resume resume)
            {
                base.Channel.SubmitResume(resume);
            }

            public void SubmitInterview(Interview interview)
            {
                base.Channel.SubmitInterview(interview);
            }

            public void SubmitNegotiation(Negotiation negotiation)
            {
                base.Channel.SubmitNegotiation(negotiation);
            }

            public void SubmitAcceptance(Acceptance acceptance)
            {
                base.Channel.SubmitAcceptance(acceptance);
            }

            public void SubmitRejection(Rejection rejection)
            {
                base.Channel.SubmitRejection(rejection);
            }

            #endregion
        }

    }
}
